﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Configuration;
using System.Xml;

namespace HY.ConfigurationSectionHandler
{
    /// <summary>
    /// 配置块处理器
    /// </summary>
    public class ConfigurationSectionHandler: IConfigurationSectionHandler
    {
        #region IConfigurationSectionHandler 成员

        public object Create(object parent, object configContext, System.Xml.XmlNode section)
        {
            List<Dictionary<String, String>> result = new List<Dictionary<string, string>>();

            foreach (XmlNode child in section.ChildNodes)
            {
                if (XmlNodeType.Element == child.NodeType)
                {
                    Dictionary<String, String> dChildAttribs = new Dictionary<string, string>();

                    foreach (XmlAttribute childAttrib in child.Attributes)
                    {
                        if (XmlNodeType.Attribute == childAttrib.NodeType)
                            dChildAttribs.Add(childAttrib.Name, childAttrib.Value);
                    }
                    result.Add(dChildAttribs);  
                }                
            }
            return result;
        }

        #endregion
    }
}
